//
//  CWHomeToolbar.swift
//  CWWeibo06
//
//  Created by ycw on 2017/7/26.
//  Copyright © 2017年 xiaowei. All rights reserved.
//

import UIKit

/**
 首页视图的toolbar
 */

class CWHomeToolbar: UIView {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    //var toolbarModel: CWStatusViewModel?
    
    //MARK: 布局界面
    func setupUI() {
        //let toolbarModel = CWStatusViewModel()
        //转发按钮
        let retweetButton = createButton(title: "转发", imageName: "timeline_icon_retweet")
        //评论按钮
        let commentButton = createButton(title: "评论", imageName: "timeline_icon_comment")
        //点赞按钮
        let unlikeButton = createButton(title: "赞", imageName: "timeline_icon_unlike")
        //第一条竖线
        let firstLine = createLineView()
        
        //第二条竖线
        let secendLine = createLineView()
        
        //添加到视图上
        addSubview(retweetButton)
        addSubview(commentButton)
        addSubview(unlikeButton)
        addSubview(firstLine)
        addSubview(secendLine)
        
        //进行约束
        retweetButton.snp.makeConstraints { (make) in
            make.top.leading.bottom.equalTo(self)
            make.width.equalTo(commentButton)
        }
        commentButton.snp.makeConstraints { (make) in
            make.top.bottom.equalTo(self)
            make.leading.equalTo(retweetButton.snp.trailing)
            make.width.equalTo(unlikeButton)
        }
        unlikeButton.snp.makeConstraints { (make) in
            make.top.bottom.trailing.equalTo(self)
            make.leading.equalTo(commentButton.snp.trailing)
        }
        firstLine.snp.makeConstraints { (make) in
            
            make.centerX.equalTo(retweetButton.snp.trailing)
            make.centerY.equalTo(self)
        }
        secendLine.snp.makeConstraints { (make) in
            
            make.centerX.equalTo(commentButton.snp.trailing)
            make.centerY.equalTo(self)
        }
        //CWNetworkTool.sharedTools.requestStatuses(accessToken: CWUserAccountViewModel.userAccountViewModel.accessToken, callBack: <#T##(Any?, Error?) -> ()#>)
    }

    
    //抽取添加按钮的方法
    fileprivate func createButton(title: String,imageName: String) -> UIButton {
        
        let button = UIButton()
        button.setTitle(title, for: .normal)
        button.setImage(UIImage(named: imageName), for: .normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        button.setTitleColor(UIColor.darkGray, for: .normal)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), for: .normal)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), for: .highlighted)
        button.adjustsImageWhenHighlighted = false
        return button
    }
    
    //创建竖线
    fileprivate func createLineView() -> UIImageView {
        
        let imgV: UIImageView = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        return imgV
    }

}
